<template>
 <lay-layout class="Pop">
    
    <lay-body>
      <lay-form :model="model" ref="layFormRef" class="MainForm" >       
          <lay-form-item label="token"    >
              <lay-input v-model="model.token"  
              
              ></lay-input>
          </lay-form-item>

          <lay-form-item label="输入参数"    >
              <lay-textarea v-model="model.pinstr"  
              style="height: 200px;"
              ></lay-textarea>
          </lay-form-item>

          <lay-form-item label="返回结果"    >
              <lay-textarea v-model="model.poutstr"  disabled 
              style="height: 200px;"
              ></lay-textarea>
          </lay-form-item>

      </lay-form>

    </lay-body>
    <lay-footer>
     
      <lay-button size="sm" type="primary" @click="toSubmit"
          prefix-icon="layui-icon-ok"
            >提交</lay-button
          >
          <lay-button size="sm" @click="toCancel" style="margin-left:40px;"
          prefix-icon="layui-icon-close"
          >取消</lay-button>

    </lay-footer>
  </lay-layout>

</template>

<script lang="ts">
import { ref, watch,reactive,onMounted } from 'vue'
import { layer } from '@layui/layer-vue'
import MyHttp from "../../library/MyHttp";  
import MyWin from "../../library/MyWin"; 
import MyPage from "../../library/MyPage"; 
import {MyExcel} from "../../library/MyExcel"; 
import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
import MyData from "../../library/MyData"; 
import {DateUtil} from "../../library/DateUtil"; 

import { useUserStore } from '../../store/user'

export default {
  props:{
      data: Object 
  },

  setup(prop:any, context:any) {
    const baseUrl="/htaction";
    const myWin=ref<any>(null);
    const userStore = useUserStore(); 
    const model = reactive<any>({ 
       token:userStore.token,
       pinstr:`{
       
    
        


       
       
}`,
       poutstr:""
    })
    const toSubmit=async()=>{
      model.poutstr="";
      let pinstr=model.pinstr.toString().trim();
      
      if(!pinstr){
        pinstr="{}";
      }
      let pinobj=JSON.parse(pinstr);
       
      var r=await new MyHttp().post(prop.data.fullUrl,pinobj,
        { 
          token:model.token
        }
      ); 
      model.poutstr=JSON.stringify(r.data, null, 2);

    } 
    const toCancel=()=>{ 
      context.emit("cancel");  
      myWin.value.close();
    }
    const getPinstr=async()=>{
      if(!prop.data.pinType){
        return;
      }
      let pin={
        id:0,
        Name:prop.data.pinType
      }
      var r=await new MyHttp().post("/htcls"+"/newobj",pin,
        { 
        }
      );  
      model.pinstr=JSON.stringify(r.data, null, 2);
    }
    onMounted(() =>{  
      myWin.value=new MyWin();
      getPinstr();
    });
    return {
      myWin,
      toSubmit,
      toCancel,
      model
       
    }
  }
}
</script>
<style scoped>
.Pop .layui-footer,
.Pop .layui-header {
  height: 50px;
  text-align: center; 
  padding-top:10px;
   
}  
.MainForm{
  width:90%;
  margin-top: 20px;;
}
</style>